//<!-- License -->
package eu.datafusion.log4soa.model.referencedata;

import static javax.persistence.CascadeType.ALL;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import eu.datafusion.log4soa.model.DataProtection;

import javax.persistence.Cacheable;

/**
 * Application is collection for services 
 * @author Ivo.Mitov@datafusion.eu
 *
 */
@Entity
@Table(name = "APPLICATIONS")
@Cacheable
public class Application extends BaseReferenceData implements Serializable {

	/**
	 * generated
	 */
	private static final long serialVersionUID = 8364460300752685950L;
	/**
	 * Services
	 */
	@OneToMany(mappedBy = "application", orphanRemoval = true, cascade = ALL)
	private Set<Service> services;

	/**
	 * @param name required immutable property <tt>name</tt> must be unique per Application class instances
	 */
	public Application(String name) {
		this(name,DataProtection.UNPROTECTED);
	}
	
	/**
	 * @param name required immutable property <tt>name</tt> must be unique per Application class instances
	 * @param dataProtection
	 */
	public Application(String name,DataProtection dataProtection) {
		this(name,dataProtection,null);
	}
	
	/**
	 * @param name required immutable property <tt>name</tt> must be unique per Application class instances
	 * @param description optional property
	 */
	public Application(String name,String description) {
		this(name,DataProtection.UNPROTECTED,description);
	}
	
	/**
	 * @param name required immutable property <tt>name</tt> must be unique per Application class instances
	 * @param dataProtection
	 * @param description optional property
	 */
	public Application(String name, DataProtection dataProtection, String description) {
		super(name,dataProtection,description);
	}

	/**
	 * default constructor required by JPA
	 */
	protected Application(){
		super();
	}

	/**
	 * Getter of the property <tt>services</tt> init if null
	 * @return  Returns the services.
	 */
	public Set<Service> getServices() {
		if(services==null){
			services = new HashSet<Service>();
		}
		return services;
	}

	/**
	 * Add Service to Application
	 * @param service  The Service to add.
	 */
	public void addService(Service service) {
		this.getServices().add(service);
	}

	@Override
	public String toString() {
		return super.toString() + ", services=" + services ;
	}


}
